﻿package {
	import flash.utils.setTimeout;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;

	//import flash.events.Event;

	//用于游戏聊天显示的类
	public class ViewChat extends Sprite {
		private var word : String;
		private var bgColor : uint = 0xFFFFFF;
		private var borderColor : uint = 0x666666;
		private var borderSize : uint = 2;
		private var cornerRadius : uint = 9;
		private var name_txt : TextField;

		public function ViewChat(str : String = "じ☆ve弦") : void {
			word = str;
			doDrawRoundRect();
			setTimeout(hide, 5000);
		}

		private function doDrawRoundRect() : void {
			var child : Sprite = new Sprite();
			child.addChild(createTxt());
			child.y = -150;
			child.graphics.beginFill(bgColor);
			child.graphics.lineStyle(borderSize, borderColor);
			child.graphics.drawRoundRect(-name_txt.width / 2 - 4, 0, name_txt.width + 8, name_txt.height, cornerRadius);
			child.graphics.lineStyle(borderSize, 0xFFFFFF);
			child.graphics.moveTo(-3, name_txt.height);
			child.graphics.lineTo(3, name_txt.height);
			child.graphics.lineStyle(borderSize, 0x666666);
			child.graphics.lineTo(0, name_txt.height + 10);
			
			//graphics.lineTo(name_txt.width/2+8,name_txt.height);
			//child.graphics.lineStyle(borderSize, 0xFFFFFF);
			child.graphics.lineTo(-3, name_txt.height);
			//child.graphics.lineStyle(borderSize, 0xFFFFFF);
			child.graphics.endFill();
			addChildAt(child, 0);
		}

		private function createTxt() : TextField {
			name_txt = new TextField();
			//var my_fmt:TextFormat=new TextFormat();
			//my_fmt.bold=true;
			//my_fmt.size=12;
			name_txt.multiline = false;
			//name_txt.wordWrap=true;
			name_txt.text = word;
			name_txt.y = 0;
			name_txt.x = -name_txt.width / 2;
			//name_txt.background=true;
			name_txt.autoSize = TextFieldAutoSize.CENTER;
			//name_txt.backgroundColor=0xff00ff
			name_txt.textColor = 0x000000;
			name_txt.selectable = false;
			return name_txt;
			//name_txt.setTextFormat(my_fmt);
		}

		private function hide() : void {
			if(parent == null) return;
			if(parent.getChildAt(0) as ViewChat) {
				parent.removeChild(this);
			}
		}
	}
}